package com.lnt.java.thread.safe;

/**
 * <p>线程安全问题展示</p>
 */
public class Ticket implements Runnable{

    private int ticket = 100;

    @Override
    public void run() {
        while (true) {
            // 模拟出票业务执行
            try {
                Thread.sleep(100);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (ticket >0) {
                // 只要有票就一直卖出
                System.out.println(Thread.currentThread().getName() + " 卖了第" + ticket--);
            }
        }
    }
}
